<template>
 <div>
        <h2>添加商品</h2>
        商品名称：<input type="text" v-model="name">
        商品价格：<input type="number" v-model="price">
        商品图片：<input type="file" id='img'>
        <button @click="add_goods">添加</button>
 </div>
</template>

<script>
 export default {
   data () {
     return {
         name:'',
         price:'',
     }
   },
   methods: {
       add_goods(){
         let img =document.getElementById('img').files[0];
         let formdata=new FormData();
         formdata.append("name",this.name);
         formdata.append("price",this.price);
         formdata.append("img",img);
         this.axios({
           url:'http://127.0.0.1:8000/app01/goods/',
           method:'post',
           data:formdata
         }).then(res=>{
           alert(res.data.msg)
         })
       }
   }
 }
</script>

<style>

 
</style>
